package com.huajx.tuopuda.client.udp.codec.auth;

import com.huajx.tuopuda.client.udp.TuopudaDirect;
import com.huajx.tuopuda.client.udp.TuopudaUtil;
import com.huajx.tuopuda.client.udp.codec.AbstractCodec;

/**
 * 读取权限[1095]
 *
 * @author: lisa 叶新华
 * @create: 2019-09-27 17:45
 */
public class ReadAuthCodec extends AbstractCodec {
    private final static int function = TuopudaDirect.D_1095;

    private int index;

    private ReadAuthCodec(int sn) {
        setSn(sn);
    }
    private ReadAuthCodec(int sn, int index) {
        this(sn);
        this.index = index;
    }

    public static ReadAuthCodec getInstance(int sn, int index) {
        return new ReadAuthCodec(sn, index);
    }

    @Override
    public byte[] encode() {
        return encode(getSn(), function, (bytes) -> TuopudaUtil.replaceBytes(bytes, getIndex(), 5, 2));
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }
}
